﻿using System.Linq;
using System.Windows;
using AuditImitation.Graphics;
using DataLayer;

namespace СorporativeSystem
{
    /// <summary>
    /// Interaction logic for MaterialGraphicWindow.xaml
    /// </summary>
    public partial class MaterialGraphicWindow : Window
    {
        public GraphicsInfo GraphicsInfo { get; set; }

        public MaterialGraphicWindow(GraphicsInfo graphicsInfo)
        {
            InitializeComponent();
            GraphicsInfo = graphicsInfo;

            materialComboBox.ItemsSource = GraphicsInfo.AllMaterials.Select(x => x);

            graphic.DataContext = GraphicsInfo.AllMaterials.FirstOrDefault();

            materialComboBox.SelectionChanged += MaterialComboBoxSelectionChanged;
        }

        void MaterialComboBoxSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            var info = materialComboBox.SelectedItem as GraphicInfoForMaterial;

            if (info != null)
            {
                graphic.DataContext = GraphicsInfo.AllMaterials.FirstOrDefault(x => x.MaterialId == info.MaterialId);
            }
        }
    }
}
